Skip to content

Fix Wimplicit-int-conversion-on-negation#355

Closed
Conarnar wants to merge 1 commit into
dvidelabs:masterfrom
Conarnar:patch-1
Closed

Fix Wimplicit-int-conversion-on-negation#355
Conarnar wants to merge 1 commit into
dvidelabs:masterfrom
Conarnar:patch-1

Conversation

@Conarnar
Copy link
Copy Markdown

@Conarnar Conarnar commented Aug 8, 2025

Clang 21 adds the warning Wimplicit-int-conversion-on-negation which is when a smaller integer type (char, short) is negated and then converted back to to the smaller type, since negation implicitly converts the value to int.

Adding the casts here should stop the warning.

if ((sign = n < 0)) {
*p++ = '-';
n = -n;
n = (int8_t)-n;
Copy link
Copy Markdown
Collaborator

@bjosv bjosv Aug 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative seems to be n *= -1; which also silences the warning..but I don't know if that is a glitch in clang.
Feels like that also would be an implicit conversion due to integer promotion.

@mikkelfj
Copy link
Copy Markdown
Contributor

It seems this fix has found its way from other commit, so I'll close this one.

@mikkelfj mikkelfj closed this Apr 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants